import './public-path';
import Vue from 'vue';
import axios from './router/axios';
import VueAxios from 'vue-axios';
import App from './App';
import router from './router/router';
// import './permission'; // 权限
import './error'; // 日志
import './cache';//页面缓存
import store from './store';
import {loadStyle} from './util/util'
import * as urls from '@/config/env';
import Element from 'element-ui';
import {
  iconfontUrl,
  iconfontVersion
} from '@/config/env';
import i18n from './lang' // Internationalization
import './styles/common.scss';
import basicBlock from './components/basic-block/main'
import basicContainer from './components/basic-container/main'
import thirdRegister from './components/third-register/main'
import avueUeditor from 'avue-plugin-ueditor';
import website from '@/config/website';
import moment from "moment";
import echarts from 'echarts';
// import 'leaflet/dist/leaflet.css';
import './styles/leaflet.css'
import L from 'leaflet';
// import '@/lib/measure/leaflet-measure.css';
// import '@/lib/measure/leaflet-measure';
const  esri = require('esri-leaflet');
const  proj = require('proj4leaflet');

Vue.use(router);
Vue.use(VueAxios, axios);
Vue.use(Element, {
  i18n: (key, value) => i18n.t(key, value)
});
Vue.use(window.AVUE, {
  size: 'small',
  tableSize: 'small',
  i18n: (key, value) => i18n.t(key, value)
});
//注册全局容器
Vue.component('basicContainer', basicContainer);
Vue.component('basicBlock', basicBlock);
Vue.component('thirdRegister', thirdRegister);
Vue.component('avueUeditor', avueUeditor);

import BaiduMap from 'vue-baidu-map';
Vue.use(BaiduMap, {ak: '1XjLLEhZhQNUzd93EjU5nOGQ'});
// 加载相关url地址
Object.keys(urls).forEach(key => {
  Vue.prototype[key] = urls[key];
});
// 加载website
Vue.prototype.website = website;
Vue.prototype.$moment = moment;
Vue.prototype.$echarts = echarts;
// 动态加载阿里云字体库
iconfontVersion.forEach(ele => {
  loadStyle(iconfontUrl.replace('$key', ele));
});

Vue.config.productionTip = false;

Vue.prototype.$esri = esri;
Vue.prototype.$L = L;
Vue.prototype.$proj = proj;
const resolutions = window.sxwise_config.CRS_resolutions;
const epsg = window.sxwise_config.CRS_epsg;
const epsgproj = window.sxwise_config.CRS_proj;
const origin = window.sxwise_config.CRS_origin;

const $CRS_CQ = new proj.CRS(epsg,epsgproj,{
  resolutions,origin
});

Vue.prototype.$CRS_CQ = $CRS_CQ;

const gisUrl = window.sxwise_config.GIS_URL;
console.log('gisUrl',gisUrl)
Vue.prototype.$addEsri = (map) => {
  // esri.basemapLayer('Imagery').addTo(map);
  const tiledMapLayer = esri.tiledMapLayer({url:gisUrl});
  map.addLayer(tiledMapLayer);
  console.log('tiledMapLayer')
  // const dynamicLayer = esri.dynamicMapLayer({opacity: 0.8,f:'jsapi',url:gisUrl});
  // map.addLayer(dynamicLayer);


  // eslint-disable-next-line max-len
  // http://10.5.12.153:6080/arcgis/services/gas117E/MapServer/WMSServer?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities
  // eslint-disable-next-line max-len
  // http://demo.mapserver.org/cgi-bin/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&BBOX=-180,-90,180,90&SRS=EPSG:4326&WIDTH=953&HEIGHT=480&LAYERS=bluemarble,cities&STYLES=&FORMAT=image/png&TRANSPARENT=true
  // eslint-disable-next-line max-len
  // const nexrad = L.tileLayer.wms('http://192.168.100.241:6080/arcgis/rest/services/gas11/MapServer', {
  //   layers: '0',
  //   // layers: 'bluemarble,cities',
  //   format: 'image/png',
  //   // transparent: true,
  //   // attribution: 'Weather data © 2012 IEM Nexrad'
  // });
  // map.addLayer(nexrad);
  // eslint-disable-next-line max-len
  // L.marker($CRS_4509.unproject({x: parseFloat(448501.102), y: parseFloat(4420425.741)})).addTo(map)
  //   .bindPopup('北京测试地点')
  //   .openPopup();
};
// 设置L.measure样式
Vue.prototype.$setMeasureStyle = (map) => {
  L.control.measure({
    position: 'topright',
    primaryLengthUnit: 'meters',
    primaryAreaUnit:'sqmeters'
  }).addTo(map);
};
delete L.Icon.Default.prototype._getIconUrl
L.Icon.Default.mergeOptions({
  iconRetinaUrl: require('leaflet/dist/images/marker-icon-2x.png'),
  iconUrl: require('./assets/images/ea8518.png'),
  shadowUrl: require('leaflet/dist/images/marker-shadow.png')
})
Vue.mixin({
  methods:{
    transLatLng:(x,y) => $CRS_CQ.unproject({x: parseFloat(x), y: parseFloat(y)})
  }
});



// new Vue({
//   router,
//   store,
//   i18n,
//   render: h => h(App)
// }).$mount('#app')


let instance = null;
// let router = null;
function render(props = {}) {
    const { container } = props;
    // router = new VueRouter({
    //   // base: window.__POWERED_BY_QIANKUN__ ? '/cqjj' : '/',
    //   mode: 'history',
    //   base: '/cqjj',
    //   routes: [...BaseRouter, ...PageRouter]
    // });
    instance = new Vue({
        router,
        store,i18n,
        render: h => h(App)
    }).$mount(container ? container.querySelector('#app') : '#app');
}

if (!window.__POWERED_BY_QIANKUN__) {
    render();
}

export async function bootstrap() {
    console.log('[vue] vue app bootstraped');
}

export async function mount(props) {
    render(props);
}

export async function unmount() {
    instance.$destroy();
    instance.$el.innerHTML = '';
    instance = null;
    // router =null;
}

